-- bloodthirsty
-- created by panyl
-- 嗜血，受创时给在场的所有怪物增加攻击

return {
    apply = function(prop, baseValue)
        return prop[3];
    end,

    -- 进入下层触发触发
    trigger = function(who, prop, arg)
        if who.type ~= OBJECT_TYPE_MONSTER then
            return 0;
        end

        -- 增加的数值,至少1点
        local attack = who.dbase:query("attack", 0);
        local add  = math.max(math.modf(attack * prop[3] / 1000), 1);

        -- 所有在场的怪物
        for pos = 1, GRID_SIZE do
            repeat
                -- 不包含自己
                if pos == who:getPos() then
                    break;
                end

                local grid = DungeonM.getGridByPos(pos);
                local monster = grid.monster;

                -- 已经翻开的且未死亡的怪物
                if grid:isOpened() and monster and not monster:isDead() then
                    local propId = PropM.getPropId("attrib2");
                    local prop = { propId, "attack", add, -1, };

                    if #monster.dbase:queryTemp("prop", "bloodthirsty", {}) <= 0 then
                        PropM.record(monster, prop, "bloodthirsty");

                        EventMgr.fire(event.MONSTER_INFO_UPDATED, {["pos"] = monster:getPos(), });
                    end
                end
            until true;
        end

        return add;
    end,

    record = function(target, prop, path)
        return false;
    end
};
